package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.db.domain.History;
import com.mall.db.service.HistoryService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods/hc")
public class historyController extends BaseController<History>{

    @Resource(name = "historyService")
    private HistoryService hs;
    @Override
    public Map<String, Object> find(History history) {
        PageHelper.startPage(history.getPage(), history.getLimit());
        QueryWrapper qw=new QueryWrapper();
        List<History> list=hs.list();
        PageInfo<History> page=new PageInfo<>(list, history.getLimit());
        return findMap(page.getList(),page.getTotal());

    }
    @RequestMapping("/seachFind")
    public Map<String, Object> seachFind(History history) {
        PageHelper.startPage(history.getPage(), history.getLimit());
        QueryWrapper qw=new QueryWrapper();
        if(!StringUtils.isEmpty(history.getUserId()))
        {
            qw.eq("user_id", history.getUserId());
        }
        if(!StringUtils.isEmpty(history.getUserId()) && !StringUtils.isEmpty(history.getKeyword())){
            qw.or();
        }
        if(!StringUtils.isEmpty(history.getKeyword()))
        {
            qw.like("keyword", history.getKeyword());
        }
        List<History> list=hs.list(qw);
        PageInfo<History> page=new PageInfo<>(list, history.getLimit());
        return findMap(page.getList(),page.getTotal());
    }
}
